package com.wetao.module_user.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;

import com.wetao.lib_common.bean.response.AreaSchoolInfo;
import com.wetao.lib_common.bean.response.Loginbean_CoachClass;
import com.wetao.lib_common.view.OnMultiClickListener;
import com.wetao.module_user.R;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class SchoolRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private Context mContext;
    private List<AreaSchoolInfo> mList = new ArrayList<>();

    public SchoolRecyclerAdapter(Context context, List<AreaSchoolInfo> list) {
        mContext = context;
        mList.clear();
        mList.addAll(list);
    }

    public void setData(List<AreaSchoolInfo> list) {
        mList.clear();
        mList.addAll(list);
    }

    @NonNull
    @NotNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.user_adapter_item_school, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;

        viewHolder.tvInfo.setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {
                if(null != mOnItemClickListener) {
                    mOnItemClickListener.onItemClick(position, mList);
                }
            }
        });

        viewHolder.tvInfo.setText(mList.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvInfo;
        public ViewHolder(View itemView) {
            super(itemView);
            tvInfo = itemView.findViewById(R.id.tv_info);
        }
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }
    OnItemClickListener mOnItemClickListener;
    public interface OnItemClickListener {
        void onItemClick(int position, List<AreaSchoolInfo> listModel);
    }
}
